#include<bits/stdc++.h>
using namespace std;
string s1[1010],s2[1010],v[1000100],v1[70000],v2[70000],v3[70000],v4[70000],v5[70000];
int chk(string s)
{
	int x1=1,x2=1,x3=1,x4=1,x5=1,f=1,p=0,k;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.'||s[i]==':')
		   f++,p=0;
		if(s[i]=='0'&&p==0)
		    k=1;
		while(s[i]!='.'&&f==1)
			x1=x1*10+s[i]-48,p++;
		while(s[i]!='.'&&f==2)
			x2=x2*10+s[i]-48;
		while(s[i]!='.'&&f==3)
			x3=x3*10+s[i]-48;
		while(s[i]!='.'&&f==4)
			x4=x4*10+s[i]-48;
		while(s[i]!='.'&&f==5)
		    x5=x5*10+s[i]-48;
	}
	if(v[x1+x2+x3+x4+x5]==1&&v1[x1]==1&&v2[x2]==1&&v3[x3]==1&&v4[x4]==1&&v5[x5]==1)
	    return 1;
	else if(v[x1+x2+x3+x4+x5]==1&&v1[x1]==1&&v2[x2]==1&&v3[x3]==1&&v4[x4]==1&&v5[x5]==1&&x1>255&&x1<0&&x2>255&&x2<0&&x3>255&&x3<0&&x4>255&&x4<0&&x5<0&&x5>65535)
	     return 2;
	else if(v[x1+x2+x3+x4+x5]==1&&v1[x1]==1&&v2[x2]==1&&v3[x3]==1&&v4[x4]==1&&v5[x5]==1&&k==1)
	     return 3;
		 else if(k==1)
		     return 4;
		else if(x1>255&&x1<0&&x2>255&&x2<0&&x3>255&&x3<0&&x4>255&&x4<0&&x5<0&&x5>65535)
		      return 5;     
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
	cin>>s1[i]>>s2[i];
}
for(int i=1;i<=n;i++)
{
	if(s1[i]=="Server"&&chk(s1[i])==1)
	   cout<<"FAIL"<<endl;
	else if(s1[i]=="Server"&&chk(s1[i])==2)
	   cout<<"ERR"<<endl;
	else if(s1[i]=="Server"&&chk(s1[i])==3)
}
		
	
	return 0;
}
